home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / d.t.p / utils / propage / donsgenies / donsgenies.lha / Don'sGenies / MulticolourText.pprx < prev    next >
Text File  |  1993-05-25  |  3KB  |  85 lines

  1. /* This Genie applies random colours to a selected block of text. Warnings: it is slow, it increases the length of the selected text by a factor of 8 or 9 (because of all the style codes needed), and it slows ProPage down to a crawl. So only do it at the end when you have got everything else right.
  2.  
  3. Written by Don Cox  ©  Dec 92  Not Public Domain. All rights reserved. */
  4.  
  5. trace n
  6. signal on error
  7. signal on syntax
  8. address command
  9.  
  10. if word(ppm_GetState(), 1) ~= 3 then exit_msg("You must be in edit mode to use this Genie")
  11.  
  12. text = ppm_GetBlockText(0)
  13. if text = '' then exit_msg("No text selected")
  14.  
  15.  
  16. collist = ppm_GetColorList()
  17. collist = substr(collist, pos('0a'x, collist) + 1) /* It begins with a number */
  18. chosen = ppm_SelectFromList("Select colours",36,24,1,collist)
  19. if chosen = "" then exit_msg("No colours chosen")
  20.  
  21. n=1
  22. do forever  /* put colours into a compound variable  */
  23.     parse var chosen acolour "0a"x chosen
  24.     if acolour = "" then break
  25.     colours.n = acolour
  26.     n=n+1
  27.     end
  28. colournumber = n-1
  29.  
  30. call ppm_ShowStatus("  Processing text...")
  31.  
  32. /* Split into sections to avoid trouble with ARexx's limit of 64k on length of strings  */
  33. sections = (length(text)%2000)+1
  34. do i=1 to sections
  35.     texts.i.endofsection = 2000
  36.     if i = sections then texts.i.endofsection = length(text)//2000
  37.     texts.i.thisSection = substr(text, (2000*(i-1))+1, texts.i.endofsection)
  38.     end
  39.  
  40. do i = 1 to sections
  41.     position = 1
  42.     newtext = ""
  43.     do until position = texts.i.endofsection+1
  44.         randcol = random(1,colournumber,time("s"))
  45.         thiscolour = colours.randcol
  46.         randbase = "\c<"||thiscolour||">"
  47.         nextchar = substr(texts.i.thisSection, position, 1)
  48.         newtext = newtext||randbase||nextchar
  49.         position = position+1
  50.         end
  51.     if i = 1 then call ppm_SaveText("PPage:textfile.temp",newtext)
  52.     if i>1 then call ppm_SaveMoreText("PPage:textfile.temp",newtext)
  53. end
  54.  
  55. call ppm_ShowStatus("  Removing old text...")
  56. success = ppm_Cut()
  57. if success ~= 1 then exit_msg("Cut failed")
  58. call ppm_ShowStatus("  Inserting new text...")
  59. success = ppm_InsertFile("PPage:textfile.temp")
  60. if success~=1 then exit_msg("Failed inserting altered text")
  61.  
  62. "delete PPage:textfile.temp"
  63. call exit_msg()
  64. end
  65.  
  66.  
  67.  
  68. /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
  69.  
  70. error:
  71. syntax:
  72.     do
  73.     exit_msg("Genie failed due to error: "errortext(rc))
  74.     end
  75.  
  76. exit_msg:
  77.     do
  78.     parse arg message
  79.     if message ~= "" then
  80.     call ppm_Inform(1,message,"Resume")
  81.     call ppm_ClearStatus()
  82.     exit
  83.     end
  84.  
  85.